home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Book Chapters / 11 - Porting / Sample Code / CursorStuff.c next >
Text File  |  1995-06-02  |  3KB  |  104 lines

  1. /************************************************************************************
  2.  *                                                                                                                                                                    *
  3.  *    CursorStuff.c                                                                                                                                        *
  4.  *                                                                                                                                                                    *
  5.  *    ©1995 Douglas Grounds. All Rights Reserved.                                                                            *
  6.  *                                                                                                                                                                    *
  7.  *    This file contains functions to spin and set the cursor. If the cursor has            *
  8.  *    already been set as specified, nothing happens, which avoids continuously                *
  9.  *    flashing the cursor, which is really annoying.                                                                    *
  10.  *                                                                                                                                                                    *
  11.  ************************************************************************************/
  12.  
  13. #include <QuickDraw.h>
  14. #include <Resources.h>
  15. #include <ToolUtils.h>
  16.  
  17. #include "CursorStuff.h"
  18.  
  19. short        gCursID = 0;
  20. long        gCursChange = 0L;
  21.  
  22. #define    kBaseCursorId        256
  23. #define kMaxCursorId        263
  24.  
  25. /******************************************************
  26.  *    myInitCursor.                                                                            *
  27.  *                                                                                                        *
  28.  *    Initializes the cursor.                                                        *
  29.  ******************************************************/
  30.  
  31. void myInitCursor (void)
  32. {
  33.     if (gCursID != 0)
  34.         InitCursor();
  35.     
  36.     gCursID = 0;
  37. }
  38.  
  39. /******************************************************
  40.  *    spinCursor.                                                                                *
  41.  *                                                                                                        *
  42.  *    Spins the "beach ball" cursor. No initialization    *
  43.  *    is necessary. This is most effective when called    *
  44.  *    from within loops.                                                                *
  45.  ******************************************************/
  46.  
  47. void spinCursor (void)
  48. {
  49.     if ((TickCount() - gCursChange) < 10L)
  50.         return;
  51.     
  52.     if ((gCursID < kBaseCursorId) || (gCursID >= kMaxCursorId))
  53.         gCursID = kBaseCursorId;
  54.     
  55.     mySetCursor(gCursID + 1);
  56. }
  57.  
  58. /******************************************************
  59.  *    mySetCursor.                                                                            *
  60.  *                                                                                                        *
  61.  *    Sets the cursor to the specified cursor ID. If        *
  62.  *    a color cursor is available, it is used, other-        *
  63.  *    wise, a black & white cursor is used.                            *
  64.  ******************************************************/
  65.  
  66. void mySetCursor (short cursID)
  67. {
  68.     CCrsrHandle        clrCurs;
  69.     CursHandle        curs;
  70.     
  71.     if (cursID == gCursID)
  72.         return;
  73.         
  74.     if (cursID == -1)
  75.     {
  76.         if (gCursID != -1)
  77.         {
  78.             gCursID = -1;
  79.             HideCursor();
  80.         }
  81.     }
  82.     else if (gCursID == -1)
  83.         myInitCursor();
  84.         
  85.     clrCurs = NULL;
  86.     clrCurs = GetCCursor(cursID);
  87.     if ((clrCurs == NULL) || (ResError()))
  88.     {
  89.         curs = GetCursor(cursID);
  90.         if ((curs) && (!ResError()))
  91.         {
  92.             SetCursor(*curs);
  93.             gCursID = cursID;
  94.             gCursChange = TickCount();
  95.         }
  96.     }
  97.     else
  98.     {
  99.         SetCCursor(clrCurs);
  100.         gCursID = cursID;
  101.         gCursChange = TickCount();
  102.     }
  103. }
  104.